#!/bin/sh

MYSQL=`which mysql`

DB="visualpun"
DBUSER="visualpun"
DBPASS="sdf09umXu"

DUMPFILE=`find dumps -name 200*.sql | sort -r | head -1`

if [ $# = 1 ]
then
	if [ ! -f "$1" ]
	then
		echo "Specific dump $1 not found"
		exit 1
	fi

	echo "Using specific dump $1"
	DUMPFILE="$1"
fi

echo "Newest dump found: $DUMPFILE"
ls -lh $DUMPFILE
#echo "Date: " `stat -t "%F" $DUMPFILE`

read -p "Really install $DUMPFILE? (y/n)"

if [ "$REPLY" == "y" ]
then
	echo "Installing $DUMPFILE"
	$MYSQL -u $DBUSER -p$DBPASS < "$DUMPFILE"
else
	echo "User aborted update"
fi

exit 0
